<template>
    <div class="container-common course-information-resource">
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item>课程信息</el-breadcrumb-item>
            <el-breadcrumb-item>课程资源</el-breadcrumb-item>
        </el-breadcrumb>
        <el-table
                :data="tableData"
                border
                style="width: 100%">
            <el-table-column
                    prop="filename"
                    label="文件名">
            </el-table-column>
            <el-table-column
                    label="操作"
                    width="300">
                <template slot-scope="scope">
                    <el-button
                            @click="handleDownload(scope.row)"
                            type="text"
                            size="large">下载</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
    import Api from '@utils/api';
    import { mapGetters } from 'vuex';

    export default {
        name: "resource",
        data () {
            return {
                tableData: []
            }
        },
        computed: {
            ...mapGetters([
                'getCurrentCourseId'
            ])
        },
        methods: {
            handleDownload (data) {
                window.open('http://39.105.144.7:5002/api/download?UUID=' + data.id);
            }
        },
        created () {
                Api({
                    method: 'post',
                    url: '/getResourceList',
                    data: {
                        type: 'course',
                        id: this.getCurrentCourseId
                    }
                }).then(res => {
                    if (res.data && res.data.data && res.data.data.length) {
                        this.tableData = res.data.data.map(item => {
                            return {
                                id: item.id,
                                filename: item.filename
                            }
                        });
                    }
                });
        }
    }
</script>